package com.zr.daoimpl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.zr.dao.UserdaoSCM;
import com.zr.model.User;

/**
 * @author  shichongming
 * @E-mail: 
 * @date 创建时间：2017年6月29日 上午9:15:08 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */
@Repository("userDao")
public class UserdaoimplSCM<T> extends BaseDaOImpl implements UserdaoSCM{

	
	@Override
	/**
	 * 账号验证
	 * 
	 * */
	public int findUidByUname(String uname){
		
				String hql = " from User u where u.uname=:uname";
				
				Query query = this.getCurrentSession().createQuery(hql);
				query.setString("uname", uname);
				List<User>  obj = query.list();							
				return obj.get(0).getUid();
	}

	@Override
	/**
	 * 登录验证
	 * 
	 * */
	public User findUidByUnameAndUpw(String uname, String upw) {
		String hql = " from User u where u.uname=:uname and u.upsw=:upsw";		
		Query query = this.getCurrentSession().createQuery(hql);
		query.setString("uname", uname);
		query.setString("upsw", upw);
		List<User>  obj = query.list();
		return obj.get(0);		
	}

	/**
	 * 登录之后修改状态，实行单点登录
	 * */	
	@Override
	public void updateUserUstate(int uid) {
		
		User u = (User) this.getCurrentSession().load(User.class, Integer.valueOf(uid));
        u.setUstate("已登录");
		
	}

	
	
	@Override
	public void updatesignOutSystem(int uid) {
		 System.out.println(213131321);
		 String hql="update User user set user.ustate='未登录' where user.uid=:uid";
		 Query query=this.getCurrentSession().createQuery(hql); 
		 query.setInteger("uid", uid);
		 int ret=query.executeUpdate(); 
	}

	
	


	
	
	
	
	

	
	
}
